{ INFORMATICS.MCCME.RU
  Problem statement: http://informatics.mccme.ru/moodle/mod/statements/view3.php?chapterid=679
  Verdict: Accepted
}
var i,n,j,l,r,t,k:integer; min,cur:int64; a:array[1..101] of integer; m:array[1..101,1..101] of int64;
begin
assign(input,'input.txt');
assign(output,'output.txt');
reset(input);
rewrite(output);
readln(n);
for i:=1 to n do fillchar(m[i],sizeof(m[i]),0);
for i:=1 to n do read(a[i]);
for t:=1 to n-2 do begin
    for l:=1 to n-1-t do begin
        min:=-1;
        r:=l+1+t;
        for k:=l+1 to r-1 do begin
            cur:=m[l][k]+a[l]*a[k]*a[r]+m[k][r];
            if (min>cur) or (min=-1) then min:=cur;
        end;
        m[l][r]:=min;
    end;
end;
writeln(m[1][n]);
end.